package com.hmall.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

public class PrintAnyGatewayFilterFactory extends AbstractGatewayFilterFactory {
    @Override
    public GatewayFilter apply(Object config) {
        //这是自定义过滤器,还可以自定义参数但是非常不常用,我们在这里写完之后,还要去网关里面配置一下,加给谁
       return new GatewayFilter() {
           @Override
           public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
               ServerHttpRequest request = exchange.getRequest();
               //过滤器执行了
               System.out.println("过滤器执行了");

               //这是放行
               return chain.filter(exchange);
           }
       };
    }
}
